
import Head from 'next/head'

<Head>
  <script>
    {
      `(function() {
         var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e60fb290e204e04c5cb6f79b0ac1e697";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
       })();`
    }
  </script>
</Head>

![LangChain](https://pica.zhimg.com/50/v2-56e8bbb52aa271012541c1fe1ceb11a2_r.gif)




Pipeline
===


PipelineAI允许您在云中规模运行您的ML模型。它还提供API访问[多个LLM模型](https://pipeline.ai)。

本教程介绍了如何使用[PipelineAI](https://docs.pipeline.ai/docs)来使用Langchain。

安装pipeline-ai[#](#install-pipeline-ai "跳转到标题")
----------------------------------------------

使用`pip install pipeline-ai`安装`pipeline-ai`库是使用`PipelineAI` API，也称为`Pipeline Cloud`所必需的。

```python
# Install the package
!pip install pipeline-ai

```

导入[#](#imports "跳转到标题")
-----------------------

```python
import os
from langchain.llms import PipelineAI
from langchain import PromptTemplate, LLMChain

```

设置环境API密钥[#](#set-the-environment-api-key "跳转到标题")
--------------------------------------------------

Make sure to get your API key from PipelineAI. Check out the [cloud quickstart guide](https://docs.pipeline.ai/docs/cloud-quickstart). You’ll be given a 30 day free trial with 10 hours of serverless GPU compute to test different models.

```python
os.environ["PIPELINE_API_KEY"] = "YOUR_API_KEY_HERE"

```

实例化PipelineAI [#](#create-the-pipelineai-instance "Permalink to this headline")
-----------------------------------------------------------------------------------------------

当实例化PipelineAI时，您需要指定要使用的管道的ID或标签，例如 `pipeline_key = "public/gpt-j:base"`。

然后，您可以选择传递其他与管道特定的关键字参数：

```python
llm = PipelineAI(pipeline_key="YOUR_PIPELINE_KEY", pipeline_kwargs={...})

```

问答提示模板[#](#create-a-prompt-template "Permalink to this headline")
-----------------------------------------------------------------------------------

我们将创建一个问答提示模板。

```python
template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

```

初始化LLMChain[#](#initiate-the-llmchain "Permalink to this headline")
-----------------------------------------------------------------------------

```python
llm_chain = LLMChain(prompt=prompt, llm=llm)

```

Run the LLMChain[#](#run-the-llmchain "Permalink to this headline")
-------------------------------------------------------------------

提供一个问题并运行LLMChain。

```python
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.run(question)

```

